package org.lhq.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.lhq.entity.User;
import org.lhq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: admin-service
 * @description: 管理员管理用户
 * @author: Wang defa
 * @create: 2021-01-05 11:57
 */

@RestController
@Api(tags = "管理员管理用户")
@RequestMapping("userManage")
public class AdminUserController {
    @Autowired
    private UserService userService;

    @GetMapping("{id}")
    public User getUser(@PathVariable("id") Long id){
        return userService.getUserById(id);
    }
    @PostMapping("editTable")
    public void updateUser(User user){
        userService.updateUserInfoById(user);
    }
    @PostMapping("deleteTable")
    public void deleteUser(Long id){
        userService.deleteUserById(id);
    }
    @PostMapping("addTable")
    public Boolean saveUser(User user){
        return userService.saveUser(user);
    }
    @PostMapping("batchDeleteTable")
    public Boolean batchDeleteTable(String batchId){
        List<String> idList = StrUtil.split(batchId,',');
        List<Long> userIds = idList.stream().map(Long::valueOf).collect(Collectors.toList());
        return userService.batchDeleteTable(userIds);
    }
    @PostMapping("userTable")
    public Page<User> queryList(User user, Long page, Long size){
        return this.userService.getUserPage(user,size,page);
    }
}
